package com.whp.openapi.web.controller;

import com.whp.openapi.common.ResponseResult;
import com.whp.openapi.common.ResultTable;
import com.whp.openapi.entity.Customer;
import com.whp.openapi.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author whp
 * @date 2021/11/25
 */
@RestController
@RequestMapping("/customer")
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    /**
     * 客户管理：搜索、分页
     * @param page
     * @param limit
     * @param name
     * @param state
     * @return
     */
    @RequestMapping("/table")
    public ResultTable table(@RequestParam(defaultValue = "1") Integer page,
                             @RequestParam(defaultValue = "10") Integer limit,
                             String name,
                             Integer state) {
        return customerService.table(page, limit, name, state);
    }

    /**
     * 删除
     * @param ids
     * @return
     */
    @RequestMapping("/del")
    public ResponseResult delCustomer(Integer[] ids) {
        return customerService.delCustomer(ids);
    }

    /**
     * 添加
     * @param customer
     * @return
     */
    @RequestMapping("/add")
    public ResponseResult addCustomer(Customer customer) {
        return customerService.addCustomer(customer);
    }

    /**
     * 编辑（修改客户信息）
     * @param customer
     * @return
     */
    @RequestMapping("/update")
    public ResponseResult updateCustomer(Customer customer) {
        return customerService.updateCustomer(customer);
    }

    /**
     * 获取所有客户（应用管理、充值管理）
     * @return
     */
    @RequestMapping("/tree")
    public List<Customer> getAllCustomer() {
        return customerService.getAllCustomer();
    }
}
